    
package TransportesMarroquin;


import com.mysql.jdbc.Connection;

import java.awt.event.ActionEvent; 
import java.awt.event.KeyEvent; 
import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 
import javax.swing.JTextField;
import com.mysql.jdbc.ResultSetMetaData;
import com.mysql.jdbc.Statement;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.awt.Toolkit;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

public class ViajeSelect extends javax.swing.JFrame {

 int num;
 int cve;
Limitador limkil = new Limitador(11);
Limitador limlicpil = new Limitador(13);
Limitador limnomcli = new Limitador(50);
Limitador limnompil = new Limitador(50);
Limitador limorigen = new Limitador(250);
Limitador limtelcli = new Limitador(8);
Limitador limvulto = new Limitador(11);
Limitador limccodv = new Limitador(11);
Limitador limcplav = new Limitador(7);
Limitador limdestino = new Limitador(250);
Limitador limempcli = new Limitador(50);
Limitador limfecha = new Limitador(16);
    /** Creates new form ViajeSelect */
    public ViajeSelect(int num) {
         initComponents();
         this.num=num;
         id.setText(""+num);
         acep.setVisible(false);   // muestro aceptar.
        bcan.setVisible(false);
    kilo.setDocument(limkil);
    licpil.setDocument(limlicpil);
    nomcli.setDocument(limnomcli);
    nompil.setDocument(limnompil);
    origen.setDocument(limorigen);
    telcli.setDocument(limtelcli);
    vulto.setDocument(limvulto);
    ccodv.setDocument(limccodv);
    cplav.setDocument(limcplav);
    destino.setDocument(limdestino);
    empcli.setDocument(limempcli);
    fecha.setDocument(limfecha);
        try {

                // coneccion a la base de datos
        MysqlDataSource datasource= new MysqlDataSource();
        datasource.setUser("root");
        datasource.setPassword("");
        datasource.setDatabaseName("practicasp8");
        datasource.setServerName("localhost");

          Connection conexion = (Connection) datasource.getConnection();


        Statement s = (Statement) conexion.createStatement();

 // query database
 ResultSet resultSet = s.executeQuery( "SELECT * FROM viaje where idviaje="+num);
        ResultSetMetaData metaData = (ResultSetMetaData) resultSet.getMetaData();
         int numerodecolumnas = metaData.getColumnCount();

       while (resultSet.next()){

        for(int i=1;i<=numerodecolumnas;i++){
             switch(i){
                 // creo este switch par delimitar el nombre de los label ya establecidos :D
                 case 1:
                     id.setText(""+resultSet.getObject(i));
                   break;
                 case 3:
                     nomcli.setText(""+resultSet.getObject(i));
                   break;
                case 4:
                     nomcli.setText(""+nomcli.getText()+" "+resultSet.getString(i));
                   break;
                 case 6:
                     empcli.setText(""+resultSet.getObject(i));
                   break;
                 case 7:
                     telcli.setText(""+resultSet.getObject(i));
                   break;
                 case 9:
                     nompil.setText(""+resultSet.getObject(i));
                   break;
                 case 10:
                     nompil.setText(""+nompil.getText()+resultSet.getObject(i));
                   break;    
                 case 11:
                     licpil.setText(""+resultSet.getObject(i));
                 break;
                 case 12:
                     ccodv.setText(""+resultSet.getObject(i));
                   break;    
                 case 14:
                     cplav.setText(""+resultSet.getObject(i));
                 break;    
                 case 15:
                     origen.setText(""+resultSet.getObject(i));
                   break;
                 case 16:
                     destino.setText(""+resultSet.getObject(i));
                   break;
                 case 17:
                     vulto.setText(""+resultSet.getObject(i));
                   break;
                 case 18:
                     fecha.setText(""+resultSet.getObject(i));
                   break;
                 case 19:
                     kilo.setText(""+resultSet.getObject(i));
                   break;
                 
                 default:
                     ;
                   break;

             }

         } // fin del for
       } // fin del while

        } catch (SQLException ex) {
            Logger.getLogger(ClienteSelect.class.getName()).log(Level.SEVERE, null, ex);

        }
    }

    private ViajeSelect() {
        
    }
    

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nomcli = new javax.swing.JTextField();
        empcli = new javax.swing.JTextField();
        licpil = new javax.swing.JTextField();
        nompil = new javax.swing.JTextField();
        telcli = new javax.swing.JTextField();
        destino = new javax.swing.JTextField();
        fecha = new javax.swing.JTextField();
        origen = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        vulto = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        kilo = new javax.swing.JTextField();
        breg = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        id = new javax.swing.JLabel();
        lnum1 = new javax.swing.JLabel();
        bgas = new javax.swing.JButton();
        cplav = new javax.swing.JTextField();
        ccodv = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        bconf = new javax.swing.JButton();
        bcan = new javax.swing.JButton();
        acep = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        bbul = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        nomcli.setEnabled(false);
        nomcli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nomcliActionPerformed(evt);
            }
        });
        nomcli.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                nomcliKeyTyped(evt);
            }
        });

        empcli.setEnabled(false);
        empcli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                empcliActionPerformed(evt);
            }
        });
        empcli.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                empcliKeyTyped(evt);
            }
        });

        licpil.setEnabled(false);
        licpil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                licpilActionPerformed(evt);
            }
        });

        nompil.setEnabled(false);
        nompil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nompilActionPerformed(evt);
            }
        });
        nompil.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                nompilKeyTyped(evt);
            }
        });

        telcli.setEnabled(false);
        telcli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                telcliActionPerformed(evt);
            }
        });
        telcli.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                telcliKeyTyped(evt);
            }
        });

        destino.setEnabled(false);
        destino.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                destinoActionPerformed(evt);
            }
        });
        destino.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                destinoKeyTyped(evt);
            }
        });

        fecha.setEnabled(false);
        fecha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fechaActionPerformed(evt);
            }
        });

        origen.setEnabled(false);
        origen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                origenActionPerformed(evt);
            }
        });
        origen.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                origenKeyTyped(evt);
            }
        });

        jLabel11.setText("Licencia piloto");

        jLabel3.setText("Empresa");

        jLabel2.setText("Nombre");

        jLabel5.setText("Cantidad Vulto");

        jLabel18.setText("Kilometraje");

        jLabel10.setText("Telefono");

        jLabel8.setText("Destino");

        jLabel6.setText("Origen");

        vulto.setEnabled(false);
        vulto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                vultoActionPerformed(evt);
            }
        });

        jLabel9.setText("Nombre piloto");

        jLabel7.setText("C L I E N T E ");

        jLabel13.setText("V I A J E");

        jLabel14.setText("P I L O T O");

        jLabel15.setText("Fecha");

        kilo.setEnabled(false);
        kilo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kiloActionPerformed(evt);
            }
        });
        kilo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                kiloKeyTyped(evt);
            }
        });

        breg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/regresar.png"))); // NOI18N
        breg.setText("Regresar");
        breg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bregActionPerformed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(143, 0, 0));

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Viaje");

        id.setFont(new java.awt.Font("Tahoma", 1, 18));
        id.setForeground(new java.awt.Color(255, 255, 255));
        id.setText("X");

        lnum1.setFont(new java.awt.Font("Tahoma", 1, 18));
        lnum1.setForeground(new java.awt.Color(255, 255, 255));
        lnum1.setText("No.");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 366, Short.MAX_VALUE)
                .addComponent(lnum1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(id)
                .addGap(87, 87, 87))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(id)
                    .addComponent(lnum1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bgas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/gastos.png"))); // NOI18N
        bgas.setText("Gastos");
        bgas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bgasActionPerformed(evt);
            }
        });

        cplav.setEnabled(false);
        cplav.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cplavActionPerformed(evt);
            }
        });

        ccodv.setEnabled(false);
        ccodv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ccodvActionPerformed(evt);
            }
        });
        ccodv.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                ccodvKeyTyped(evt);
            }
        });

        jLabel12.setText("Placa Vehiculo");

        jLabel16.setText("Codigo Vehiculo");

        jLabel17.setText("V E H Í C U L O ");

        bconf.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/config.png"))); // NOI18N
        bconf.setText("Configurar");
        bconf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bconfActionPerformed(evt);
            }
        });

        bcan.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cancelar.png"))); // NOI18N
        bcan.setText("Cancelar");
        bcan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bcanActionPerformed(evt);
            }
        });

        acep.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/aceptar.png"))); // NOI18N
        acep.setText("Aceptar");
        acep.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                acepActionPerformed(evt);
            }
        });

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Highway.png"))); // NOI18N

        bbul.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/1316240906_deliverables.png"))); // NOI18N
        bbul.setText("Bultos");
        bbul.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bbulActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addGap(218, 218, 218)
                        .addComponent(jLabel13))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addComponent(empcli, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(52, 52, 52)
                        .addComponent(jLabel6)
                        .addGap(58, 58, 58)
                        .addComponent(origen, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addGap(38, 38, 38)
                        .addComponent(telcli, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(52, 52, 52)
                        .addComponent(jLabel8)
                        .addGap(54, 54, 54)
                        .addComponent(destino, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(280, 280, 280)
                        .addComponent(jLabel5)
                        .addGap(20, 20, 20)
                        .addComponent(vulto, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel14)
                        .addGap(228, 228, 228)
                        .addComponent(jLabel18)
                        .addGap(37, 37, 37)
                        .addComponent(kilo, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(24, 24, 24)
                        .addComponent(nompil, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(42, 42, 42)
                        .addComponent(jLabel17))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(43, 43, 43)
                        .addComponent(nomcli, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(52, 52, 52)
                        .addComponent(jLabel15)
                        .addGap(61, 61, 61)
                        .addComponent(fecha, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(breg, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(112, 112, 112)
                                .addComponent(jLabel12)
                                .addGap(23, 23, 23)
                                .addComponent(cplav, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(57, 57, 57)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(acep, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 70, Short.MAX_VALUE)
                                    .addComponent(bgas, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                                    .addComponent(bbul, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(bcan, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(bconf, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(12, 12, 12))))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addGap(24, 24, 24)
                        .addComponent(licpil, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(42, 42, 42)
                        .addComponent(jLabel16)
                        .addGap(15, 15, 15)
                        .addComponent(ccodv, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(20, Short.MAX_VALUE))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {acep, bcan, bconf, bgas, breg});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jLabel13))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addComponent(jLabel2))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(nomcli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel15)
                    .addComponent(fecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(jLabel3))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(empcli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel6)
                    .addComponent(origen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jLabel10))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(telcli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel8)
                    .addComponent(destino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(vulto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel14)
                    .addComponent(jLabel18)
                    .addComponent(kilo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(nompil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel17)))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(licpil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel16))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(ccodv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(breg, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel12)
                            .addComponent(cplav, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(bbul)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(bgas, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(acep, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(bconf)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(bcan, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {acep, bcan, bconf, bgas, breg});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void nomcliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nomcliActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_nomcliActionPerformed

    private void empcliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_empcliActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_empcliActionPerformed

    private void licpilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_licpilActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_licpilActionPerformed

    private void nompilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nompilActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_nompilActionPerformed

    private void telcliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_telcliActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_telcliActionPerformed

    private void destinoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_destinoActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_destinoActionPerformed

    private void fechaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fechaActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_fechaActionPerformed

    private void origenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_origenActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_origenActionPerformed

    private void vultoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_vultoActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_vultoActionPerformed

    private void kiloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kiloActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_kiloActionPerformed

    private void bregActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bregActionPerformed
        dispose();
        Viaje va;

        va = new Viaje("select * from viaje");
        va.setVisible(true);
        va.setBounds(114, 107, Toolkit.getDefaultToolkit().getScreenSize().width-114, Toolkit.getDefaultToolkit().getScreenSize().height-107);

    }//GEN-LAST:event_bregActionPerformed

    private void bgasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bgasActionPerformed
        dispose();
        
        
        Gasto vap = new Gasto("select * from gasto where tipovehiculo like 'Viaje' AND idvehiculo ="+num,num,"Viaje");
        vap.setVisible(true);
        
        vap.setBounds(114, 107, Toolkit.getDefaultToolkit().getScreenSize().width-114, Toolkit.getDefaultToolkit().getScreenSize().height-107);
}//GEN-LAST:event_bgasActionPerformed

    private void cplavActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cplavActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cplavActionPerformed

    private void ccodvActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ccodvActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ccodvActionPerformed

    private void bconfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bconfActionPerformed
        // obtener el dato de la llave primaria


   //Habilito los campos de texto
    kilo.setEnabled(true);
    licpil.setEnabled(true);
    nomcli.setEnabled(true);
    nompil.setEnabled(true);
    origen.setEnabled(true);
    telcli.setEnabled(true);
    vulto.setEnabled(true);
    ccodv.setEnabled(true);
    cplav.setEnabled(true);
    destino.setEnabled(true);
    empcli.setEnabled(true);
    fecha.setEnabled(true);
        //Hago visibles y oculto ciertos botones
        acep.setVisible(true);   // muestro aceptar.
        bcan.setVisible(true);
        breg.setVisible(false);
        bconf.setVisible(false);
        bgas.setVisible(false);
        bbul.setVisible(false);


}//GEN-LAST:event_bconfActionPerformed

    private void bcanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bcanActionPerformed
            acep.setVisible(false);
            bcan.setVisible(false);
            bconf.setVisible(true);
            breg.setVisible(true);
            bgas.setVisible(true);
            bbul.setVisible(true);


        // REGRESO A OCULTAR LOS DATOS
       //Habilito los campos de texto
    kilo.setEnabled(false);
    licpil.setEnabled(false);
    nomcli.setEnabled(false);
    nompil.setEnabled(false);
    origen.setEnabled(false);
    telcli.setEnabled(false);
    vulto.setEnabled(false);
    ccodv.setEnabled(false);
    cplav.setEnabled(false);
    destino.setEnabled(false);
    empcli.setEnabled(false);
    fecha.setEnabled(false);
    }//GEN-LAST:event_bcanActionPerformed

    private void acepActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acepActionPerformed
        //  opcion
        //UPDATE


        try {
            // coneccion
            //CONFIGURAR
            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setUser("root");
            dataSource.setPassword("");
            dataSource.setDatabaseName("practicasp8");
            dataSource.setServerName("localhost");
            Connection conexion = (Connection) dataSource.getConnection();
            Statement instruccion = null;
            instruccion=(Statement) conexion.createStatement();
            // cambio los valores
            instruccion.executeUpdate("update viaje set nombre_cliente='"+nomcli.getText()+"' where idviaje="+num);
            instruccion.executeUpdate("update viaje set empresa_cliente='"+empcli.getText()+"' where idviaje="+num);
            instruccion.executeUpdate("update viaje set telefono_cliente='"+telcli.getText()+"' where idviaje="+num);
            instruccion.executeUpdate("update viaje set nombre_piloto='"+nompil.getText()+"' where idviaje="+num);
            instruccion.executeUpdate("update viaje set licencia_piloto='"+licpil.getText()+"' where idviaje="+num);
            instruccion.executeUpdate("update viaje set fecha='"+fecha.getText()+"' where idviaje="+num);
            instruccion.executeUpdate("update viaje set origen='"+origen.getText()+"' where idviaje="+num);
            instruccion.executeUpdate("update viaje set destino='"+destino.getText()+"' where idviaje="+num);
            instruccion.executeUpdate("update viaje set vulto='"+vulto.getText()+"' where idviaje="+num);
            instruccion.executeUpdate("update viaje set kilometraje='"+kilo.getText()+"' where idviaje="+num);
            instruccion.executeUpdate("update viaje set codigo_vehiculo='"+ccodv.getText()+"' where idviaje="+num);
            instruccion.executeUpdate("update viaje set placa_vehiculo='"+cplav.getText()+"' where idviaje="+num);


            JOptionPane.showMessageDialog(rootPane, "Dato cambiado exitosamente" );

            acep.setVisible(false);
            bcan.setVisible(false);
            bconf.setVisible(true);
            breg.setVisible(true);
            bgas.setVisible(true);
            bbul.setVisible(true);

            
            // bloqueo de nuevo las cajas de texto :D 
     //Habilito los campos de texto
    kilo.setEnabled(false);
    licpil.setEnabled(false);
    nomcli.setEnabled(false);
    nompil.setEnabled(false);
    origen.setEnabled(false);
    telcli.setEnabled(false);
    vulto.setEnabled(false);
    ccodv.setEnabled(false);
    cplav.setEnabled(false);
    destino.setEnabled(false);
    empcli.setEnabled(false);
    fecha.setEnabled(false);

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(rootPane, "Se ha producido un error al tratar de cambiar el dato. " );
        }

    }//GEN-LAST:event_acepActionPerformed

    private void telcliKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_telcliKeyTyped
             char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_telcliKeyTyped

    private void kiloKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_kiloKeyTyped
             char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_kiloKeyTyped

    private void ccodvKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ccodvKeyTyped
                char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_ccodvKeyTyped

    private void nomcliKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nomcliKeyTyped
       char c = evt.getKeyChar();
       if(!(Character.isLetter(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE || c== evt.VK_DEAD_TILDE)
       {
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_nomcliKeyTyped

    private void empcliKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_empcliKeyTyped
      char c = evt.getKeyChar();
       if(!(Character.isLetter(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE || c== evt.VK_DEAD_TILDE)
       {
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_empcliKeyTyped

    private void nompilKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nompilKeyTyped
         char c = evt.getKeyChar();
       if(!(Character.isLetter(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE || c== evt.VK_DEAD_TILDE)
       {
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_nompilKeyTyped

    private void origenKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_origenKeyTyped
       char c = evt.getKeyChar();
       if(!(Character.isLetter(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE || c== evt.VK_DEAD_TILDE)
       {
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_origenKeyTyped

    private void destinoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_destinoKeyTyped
       char c = evt.getKeyChar();
       if(!(Character.isLetter(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE || c== evt.VK_DEAD_TILDE)
       {
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_destinoKeyTyped

    private void bbulActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bbulActionPerformed
        dispose();
        
        
        Vulto vap = new Vulto("select * from vulto where idviaje ="+num,num);
        vap.setVisible(true);
        
        vap.setBounds(114, 107, Toolkit.getDefaultToolkit().getScreenSize().width-114, Toolkit.getDefaultToolkit().getScreenSize().height-107);
}//GEN-LAST:event_bbulActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ViajeSelect().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton acep;
    private javax.swing.JButton bbul;
    private javax.swing.JButton bcan;
    private javax.swing.JButton bconf;
    private javax.swing.JButton bgas;
    private javax.swing.JButton breg;
    private javax.swing.JTextField ccodv;
    private javax.swing.JTextField cplav;
    private javax.swing.JTextField destino;
    private javax.swing.JTextField empcli;
    private javax.swing.JTextField fecha;
    private javax.swing.JLabel id;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField kilo;
    private javax.swing.JTextField licpil;
    private javax.swing.JLabel lnum1;
    private javax.swing.JTextField nomcli;
    private javax.swing.JTextField nompil;
    private javax.swing.JTextField origen;
    private javax.swing.JTextField telcli;
    private javax.swing.JTextField vulto;
    // End of variables declaration//GEN-END:variables

}
